<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>How To Compile</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.12.4.min.js"
	integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>

<script src="../docs-assets/Bigfoot.js"></script>
<link href="../docs-assets/Bigfoot.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'How To Compile' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">core</a></li><li><a href="index.html#1">Chapter 1: Control</a></li><li><b>How To Compile</b></li></ul></div>
<p class="purpose">The long production line on which products of Inform are built, one step at a time.</p>

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>Having seen the top management of the factory, we now reach the factory
floor, which is one long production line: over 100 steps must be performed
in sequence to finish making the product. We can picture each of these
steps as carried out by a worker function: each does its work and passes
on to the next.
</p>

<p class="commentary">We group the steps into departments, which are in order of when they work:
</p>

<pre class="definitions code-font"><span class="definition-keyword">enum</span> <span class="constant-syntax">SUBDIVIDING_CSEQ</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">BUILT_IN_STUFF_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">SEMANTIC_ANALYSIS_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">ASSERTIONS_PASS_1_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">ASSERTIONS_PASS_2_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">MODEL_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">MODEL_COMPLETE_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">TABLES_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">AUGMENT_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">PHRASES_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">INTER1_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">INTER2_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">INTER3_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">INTER4_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">INTER5_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">BIBLIOGRAPHIC_CSEQ</span>
<span class="definition-keyword">enum</span> <span class="constant-syntax">FINISHED_CSEQ</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>The aim of this section is to contain as little logic as possible other
then the sequence itself.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::carry_out</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Sequence::carry_out</span></span>:<br/>What To Compile - <a href="1-wtc.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">stopwatch_timer</span><span class="plain-syntax"> *</span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Time::start_stopwatch</span><span class="plain-syntax">(</span><span class="identifier-syntax">inform7_timer</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"compilation to Inter"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_1" class="named-paragraph-link"><span class="named-paragraph">Divide into compilation units</span><span class="named-paragraph-number">2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_2" class="named-paragraph-link"><span class="named-paragraph">Build a rudimentary set of kinds, relations, verbs and inference subjects</span><span class="named-paragraph-number">2.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_3" class="named-paragraph-link"><span class="named-paragraph">Pass three times through the major nodes</span><span class="named-paragraph-number">2.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_4" class="named-paragraph-link"><span class="named-paragraph">Make the model world</span><span class="named-paragraph-number">2.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_5" class="named-paragraph-link"><span class="named-paragraph">Tables and grammar</span><span class="named-paragraph-number">2.5</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_6" class="named-paragraph-link"><span class="named-paragraph">Augment model world with low-level properties</span><span class="named-paragraph-number">2.6</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_7" class="named-paragraph-link"><span class="named-paragraph">Phrases and rules</span><span class="named-paragraph-number">2.7</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_8" class="named-paragraph-link"><span class="named-paragraph">Run any internal tests</span><span class="named-paragraph-number">2.8</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_9" class="named-paragraph-link"><span class="named-paragraph">Generate inter, part 1</span><span class="named-paragraph-number">2.9</span></a></span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_10" class="named-paragraph-link"><span class="named-paragraph">Generate inter, part 2</span><span class="named-paragraph-number">2.10</span></a></span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_11" class="named-paragraph-link"><span class="named-paragraph">Generate inter, part 3</span><span class="named-paragraph-number">2.11</span></a></span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_12" class="named-paragraph-link"><span class="named-paragraph">Generate inter, part 4</span><span class="named-paragraph-number">2.12</span></a></span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_13" class="named-paragraph-link"><span class="named-paragraph">Generate inter, part 5</span><span class="named-paragraph-number">2.13</span></a></span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP2_14" class="named-paragraph-link"><span class="named-paragraph">Generate index and bibliographic file</span><span class="named-paragraph-number">2.14</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">problem_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><a href="1-htc.html#SP11" class="function-link"><span class="function-syntax">Sequence::throw_error_if_subtasks_remain</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">FINISHED_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Complete"</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">cpu_time_used</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Time::stop_stopwatch</span><span class="plain-syntax">(</span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Compile CPU time: %d centiseconds\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">cpu_time_used</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">problem_count</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>This macro carries out a step at what we think of as "benches" in the
production line: hence the name <span class="extract"><span class="extract-syntax">BENCH</span></span>. Continuing the analogy, there is an
ongoing time and motion study: any step which takes more than 1 centisecond of
CPU time is reported to the debugging log. That isn't necessarily a sign of
something wrong: a few of these steps are always going to take serious
computation. But we want to know which ones.
</p>

<p class="commentary">As soon as any step generates problem messages, all subsequent steps are
skipped, so that each of the worker functions can assume that the
part-assembled state they receive is correct so far. This greatly simplifies
error recovery, prevents small errors in the source text leading to
cascades of problem messages, and ensures that we report problems as quickly
as possible.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">routine</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">problem_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="string-syntax">"//"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, #</span><span class="identifier-syntax">routine</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="string-syntax">"//"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">)-1; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">'_'</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1) == </span><span class="character-syntax">'_'</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Str::put_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="character-syntax">':'</span><span class="plain-syntax">); </span><span class="identifier-syntax">Str::put_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">+1, </span><span class="character-syntax">':'</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">stopwatch_timer</span><span class="plain-syntax"> *</span><span class="identifier-syntax">st</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Time::start_stopwatch</span><span class="plain-syntax">(</span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Str::clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax">, </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">routine</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">cs</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Time::stop_stopwatch</span><span class="plain-syntax">(</span><span class="identifier-syntax">st</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cs</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">".... "</span><span class="plain-syntax"> #</span><span class="identifier-syntax">routine</span><span class="plain-syntax"> </span><span class="string-syntax">"() took %dcs\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">cs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2_1" class="paragraph-anchor"></a><b>&#167;2.1. </b>Here, then, are the steps in the production line, presented without
commentary. For what they do, see the relevant sections. Note that at the
end of each stage, plugins made by compiler features are allowed to add
further steps; see <a href="1-wtc.html#SP6" class="internal">Task::advance_stage_to</a>.
</p>

<p class="commentary">Before anything else can be done, we must create an empty Inter hierarchy
into which we will "emit" an Inter program. No actual code will be emitted for
some time yet, but identifier names and type declarations need somewhere to go.
We then break the source into "compilation units" &mdash; basically, one for the
main source text and one for each extension &mdash; because the Inter hierarchy
will divide according to these units.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Divide into compilation units</span><span class="named-paragraph-number">2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">SUBDIVIDING_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Dividing source into compilation units"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-cs.html#SP4" class="function-link"><span class="function-syntax">CompilationSettings::initialise_gcs</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Emit::create_emission_tree</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Hierarchy::establish</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">GenericModule::compile</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">NameResolution::make_the_tree</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-wtc.html#SP16" class="function-link"><span class="function-syntax">Task::write_XML_headings_file</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">CompilationUnits::determine</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-wtc.html#SP8" class="function-link"><span class="function-syntax">Task::warn_about_deprecated_nests</span></a><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_2" class="paragraph-anchor"></a><b>&#167;2.2. </b>Most of the conceptual infrastructure in Inform is created by Inform source
text in the Basic Inform or Standard Rules extensions, but not basic kinds of
value such as "number", or the verb "to mean", or the meaning relation, and
so on. Those absolute basics are made here.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Build a rudimentary set of kinds, relations, verbs and inference subjects</span><span class="named-paragraph-number">2.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">BUILT_IN_STUFF_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Making built in infrastructure"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">InferenceSubjects::make_built_in</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-wtc.html#SP11" class="function-link"><span class="function-syntax">Task::make_built_in_kind_constructors</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">BinaryPredicateFamilies::first_stock</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">BootVerbs::make_built_in</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Instances::make_instances_from_Neptune</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_3" class="paragraph-anchor"></a><b>&#167;2.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Pass three times through the major nodes</span><span class="named-paragraph-number">2.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">SEMANTIC_ANALYSIS_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Pre-pass through major nodes"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">MajorNodes::pre_pass</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-wtc.html#SP7" class="function-link"><span class="function-syntax">Task::verify</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">ASSERTIONS_PASS_1_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"First pass through major nodes"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">2</span><span class="plain-syntax">, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">MajorNodes::pass_1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Tables::traverse_to_stock</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">LiteralPatterns::after_pass_1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Dialogue::after_pass_1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">ASSERTIONS_PASS_2_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Second pass through major nodes"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">MajorNodes::pass_2</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">DialogueBeats::decide_cue_topics</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">LicenceDeclaration::check_licences</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">BibliographicData::fill_licence_variables</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_4" class="paragraph-anchor"></a><b>&#167;2.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make the model world</span><span class="named-paragraph-number">2.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">MODEL_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Making the model world"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTKindDeclarations::declare_base_kinds</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Translations::traverse_for_late_namings</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">OrderingInstances::objects_in_definition_sequence</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">MODEL_COMPLETE_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Completing the model world"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">World::stages_II_and_III</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">World::stage_IV</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_5" class="paragraph-anchor"></a><b>&#167;2.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Tables and grammar</span><span class="named-paragraph-number">2.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">TABLES_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Tables and grammar"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Measurements::validate_definitions</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">BinaryPredicateFamilies::second_stock</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Tables::check_tables_for_kind_clashes</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_6" class="paragraph-anchor"></a><b>&#167;2.6. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Augment model world with low-level properties</span><span class="named-paragraph-number">2.6</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">AUGMENT_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Augment model world"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">World::stage_V</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">MappingHints::traverse_for_map_parameters</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_7" class="paragraph-anchor"></a><b>&#167;2.7. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Phrases and rules</span><span class="named-paragraph-number">2.7</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">PHRASES_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Phrases and rules"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">3</span><span class="plain-syntax">, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">LiteralPatterns::define_named_phrases</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">ImperativeDefinitions::assess_all</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Equations::traverse_to_stock</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Tables::traverse_to_stock</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTRulebooks::RulebookOutcomePrintingRule</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_8" class="paragraph-anchor"></a><b>&#167;2.8. </b>See <a href="1-itc.html" class="internal">Internal Test Cases</a> for an explanation of the alarming-looking <span class="extract"><span class="extract-syntax">exit</span></span>
here, which only happens when special runs are made for compiler testing.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Run any internal tests</span><span class="named-paragraph-number">2.8</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">debugging</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">problem_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">tests_run</span><span class="plain-syntax"> = </span><a href="1-itc.html#SP7" class="function-link"><span class="function-syntax">InternalTests::run</span></a><span class="plain-syntax">(1);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tests_run</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">exit</span><span class="plain-syntax">(0);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_9" class="paragraph-anchor"></a><b>&#167;2.9. </b>This proceeds in stages.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate inter, part 1</span><span class="named-paragraph-number">2.9</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">INTER1_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Generating inter (1)"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">4</span><span class="plain-syntax">, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTUseOptions::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTCommandGrammars::compile_non_generic_constants</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Interventions::make_all</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTKindConstructors::assign_declaration_sequence_numbers</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTKindConstructors::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTLiteralPatterns::compile</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_10" class="paragraph-anchor"></a><b>&#167;2.10. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate inter, part 2</span><span class="named-paragraph-number">2.10</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">INTER2_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Generating inter (2)"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">CompletionModule::compile</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTProperties::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTKindConstructors::compile_permissions</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">InferenceSubjects::emit_all</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Tables::complete</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTTables::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTTableColumns::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTEquations::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">ImperativeDefinitions::compile_first_block</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTDialogueBeats::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTDialogueLines::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTDialogueChoices::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTRules::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTRulebooks::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTRulebooks::compile_nros</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTActivities::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTVerbs::compile_conjugations</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTVerbs::compile_forms</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">CompilationUnits::complete_metadata</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_11" class="paragraph-anchor"></a><b>&#167;2.11. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate inter, part 3</span><span class="named-paragraph-number">2.11</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">INTER3_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Generating inter (3)"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">PhraseRequests::invoke_to_begin</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Closures::compile_closures</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-htc.html#SP10" class="function-link"><span class="function-syntax">Sequence::undertake_queued_tasks</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTRelations::compile</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTAdjectives::compile_mdef_test_functions</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-htc.html#SP10" class="function-link"><span class="function-syntax">Sequence::undertake_queued_tasks</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTPhrasebook::compile_entries</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTMappingHints::compile</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_12" class="paragraph-anchor"></a><b>&#167;2.12. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate inter, part 4</span><span class="named-paragraph-number">2.12</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">INTER4_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Generating inter (4)"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_13" class="paragraph-anchor"></a><b>&#167;2.13. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate inter, part 5</span><span class="named-paragraph-number">2.13</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">INTER5_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Generating inter (5)"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-htc.html#SP10" class="function-link"><span class="function-syntax">Sequence::undertake_queued_tasks</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTKindIDs::compile_structures</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-htc.html#SP10" class="function-link"><span class="function-syntax">Sequence::undertake_queued_tasks</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-htc.html#SP9" class="function-link"><span class="function-syntax">Sequence::allow_no_further_queued_tasks</span></a><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">TheHeap::compile_configuration</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Rules::check_response_usages</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Responses::declare_deferred_inames</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">LocalParking::compile_array</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">RTBibliographicData::IFID_text</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-htc.html#SP13" class="function-link"><span class="function-syntax">Sequence::lint_inter</span></a><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2_14" class="paragraph-anchor"></a><b>&#167;2.14. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate index and bibliographic file</span><span class="named-paragraph-number">2.14</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="1-wtc.html#SP6" class="function-link"><span class="function-syntax">Task::advance_stage_to</span></a><span class="plain-syntax">(</span><span class="constant-syntax">BIBLIOGRAPHIC_CSEQ</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"Bibliographic work"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        -1, </span><span class="identifier-syntax">debugging</span><span class="plain-syntax">, </span><span class="identifier-syntax">sequence_timer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">Hierarchy::log</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">debugging</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">problem_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">tests_run</span><span class="plain-syntax"> = </span><a href="1-itc.html#SP7" class="function-link"><span class="function-syntax">InternalTests::run</span></a><span class="plain-syntax">(2);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tests_run</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">exit</span><span class="plain-syntax">(0);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BENCH</span><span class="plain-syntax">(</span><a href="1-wtc.html#SP22" class="function-link"><span class="function-syntax">Task::specify_index_requirements</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">INTER_DA</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">InterSkill::set_debugging</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">INFORM_INTER_DA</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TextualInter::write</span><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">Emit::tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linked_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">L</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Dash::phrases_to_log</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">L</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Phrase or rule bodies for which textual Inter was requested by '***':\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pack</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">pack</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_package</span><span class="plain-syntax">, </span><span class="identifier-syntax">L</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"\n%d. Package at $6:\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">n</span><span class="plain-syntax">++, </span><span class="identifier-syntax">pack</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TextualInter::write_package</span><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">Emit::tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">pack</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP2">&#167;2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>We will define just one of the above steps here, because it works in a way
which breaks the pattern of doing everything just once. For one thing, it's
actually called twice in the above sequence.
</p>

<p class="commentary">The issue here is that each time an imperative definition is compiled to a
function, that can require other resources to be compiled in turn. The
code compiled into the function body can involve calls to functions derived
from other imperative definitions, or even the same one reinterpreted:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">To</span><span class="plain-syntax"> </span><span class="identifier-syntax">expose</span><span class="plain-syntax"> (</span><span class="identifier-syntax">X</span><span class="plain-syntax"> - </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">):</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">say</span><span class="plain-syntax"> </span><span class="string-syntax">"You admire [X]."</span>

<span class="identifier-syntax">To</span><span class="plain-syntax"> </span><span class="identifier-syntax">advertise</span><span class="plain-syntax"> (</span><span class="identifier-syntax">T</span><span class="plain-syntax"> - </span><span class="identifier-syntax">text</span><span class="plain-syntax">):</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">expose</span><span class="plain-syntax"> </span><span class="identifier-syntax">T</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">let</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">price</span><span class="plain-syntax"> </span><span class="identifier-syntax">be</span><span class="plain-syntax"> </span><span class="string-syntax">"the price tag of [a random number between 5 and 10] pounds"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">expose</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">price</span><span class="plain-syntax">.</span>

<span class="identifier-syntax">Every</span><span class="plain-syntax"> </span><span class="identifier-syntax">turn</span><span class="plain-syntax">:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">advertise</span><span class="plain-syntax"> </span><span class="string-syntax">"a valuable antique silver coffee pot"</span><span class="plain-syntax">.</span>
</pre>
<p class="commentary">Phrases are compiled on demand, but rules are always demanded, so the "every
turn" rule here is compiled; that requires "advertise" to be compiled; which
in turn requires a form of "expose X" to be compiled for X a text. But
"advertise" also needs the text substitution "the price tag of [a random number
between 5 and 10] pounds" to be compiled, and that in turn creates a further
function compilation in order to provide a context for execution of the phrase
"a random number between 5 and 10", which in turn... and so on.
</p>

<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>The only way to be sure of handling all needs here is to keep on compiling
until the process exhausts itself, and this we do with a queue of tasks to
perform.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> Suppose we have this queue:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">T1</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">T2</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">T3</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">T4</span><span class="plain-syntax"> -&gt; ...</span>
</pre>
<p class="commentary">and we are working on T2. That uncovers the need for three further tasks
X1, X2, X3: those are added immediately after T2 &mdash;
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">T1</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">T2</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">X1</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">X2</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">X3</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">T3</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">T4</span><span class="plain-syntax"> -&gt; ...</span>
</pre>
<p class="commentary">Thus we never reach T3 until T2 has been completely exhausted, including its
secondary tasks. To get a sense of how this works in practice, try:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Include</span><span class="plain-syntax"> </span><span class="identifier-syntax">task</span><span class="plain-syntax"> </span><span class="identifier-syntax">queue</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">debugging</span><span class="plain-syntax"> </span><span class="identifier-syntax">log</span><span class="plain-syntax">.</span>
</pre>
<ul class="footnotetexts"><li class="footnote" id="fn:1"><p class="inwebfootnote"><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> Until 2021 this process is structured as a set of coroutines rather than a
queue. C does not strictly speaking support coroutines, though that hasn't stopped
hackers from using assembly language to manipulate return addresses on the C call
stack, and/or use
<a href="https://en.wikipedia.org/wiki/Duff%27s_device" class="external">Duff's device</a>. It never
quite came to that here, but it was sometimes difficult to reason about.
<a href="#fnref:1" title="return to text"> &#x21A9;</a></p></li></ul>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>A task is abstracted as being a call to a function, called the "agent", with
a pointer to the relevant data.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">caused_by</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">next_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">void</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">agent</span><span class="plain-syntax">)(</span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_sentence_when_queued</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">description</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="function-syntax">Sequence::new_subtask</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Sequence::new_subtask</span></span>:<br/><a href="1-htc.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">agent</span><span class="plain-syntax">)(</span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *),</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">desc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">caused_by</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">agent</span><span class="plain-syntax"> = </span><span class="identifier-syntax">agent</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">data</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">current_sentence_when_queued</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">description</span><span class="plain-syntax"> = </span><span class="identifier-syntax">desc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure compilation_subtask is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>Each call to <a href="1-htc.html#SP10" class="internal">Sequence::undertake_queued_tasks</a> works methodically through
the queue until everything is done.
</p>

<p class="commentary">The queue is a linked list of <span class="extract"><span class="extract-syntax">compilation_subtask</span></span> objects in between <span class="extract"><span class="extract-syntax">first_task</span></span>
and <span class="extract"><span class="extract-syntax">last_task</span></span>. (The queue is empty if and only if both are <span class="extract"><span class="extract-syntax">NULL</span></span>.) The queue
only grows, and never has items removed.
</p>

<p class="commentary">A marker called <span class="extract"><span class="extract-syntax">last_task_undetaken</span></span> shows how much progress we have made in
completing the tasks queued: so, when this is equal to <span class="extract"><span class="extract-syntax">last_task</span></span>, there is
nothing to do. Another marker called <span class="extract"><span class="extract-syntax">current_task</span></span> is set only when a task
is under way, and is <span class="extract"><span class="extract-syntax">NULL</span></span> at all other times.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">first_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">last_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">last_task_undetaken</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">current_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, *</span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">task_queue_is_closed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>The rest of Inform, if it wants to schedule a compilation task, should call
one of these two functions:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::queue</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">agent</span><span class="plain-syntax">)(</span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *),</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">desc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><a href="1-htc.html#SP6" class="function-link"><span class="function-syntax">Sequence::new_subtask</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">agent</span><span class="plain-syntax">, </span><span class="identifier-syntax">gp</span><span class="plain-syntax">, </span><span class="identifier-syntax">desc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP8_1" class="named-paragraph-link"><span class="named-paragraph">Queue the task</span><span class="named-paragraph-number">8.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::queue_at</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax"> (*</span><span class="identifier-syntax">agent</span><span class="plain-syntax">)(</span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *),</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">gp</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">desc</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">at</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><a href="1-htc.html#SP6" class="function-link"><span class="function-syntax">Sequence::new_subtask</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">agent</span><span class="plain-syntax">, </span><span class="identifier-syntax">gp</span><span class="plain-syntax">, </span><span class="identifier-syntax">desc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">current_sentence_when_queued</span><span class="plain-syntax"> = </span><span class="identifier-syntax">at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-htc.html#SP8_1" class="named-paragraph-link"><span class="named-paragraph">Queue the task</span><span class="named-paragraph-number">8.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8_1" class="paragraph-anchor"></a><b>&#167;8.1. </b>New entries are inserted in the queue at two write positions:
</p>

<ul class="items"><li>&#9679; after the <span class="extract"><span class="extract-syntax">last_task</span></span>, i.e., at the back, if no task is currently going on; or
</li><li>&#9679; after the <span class="extract"><span class="extract-syntax">current_horizon</span></span> marker, i.e., after the current task finishes.
</li></ul>
<p class="commentary">In the case where we are currently in the middle of what was the last task
when it started, these two positions will be the same, so we sometimes need
to advance <span class="extract"><span class="extract-syntax">last_task</span></span> even when <span class="extract"><span class="extract-syntax">current_horizon</span></span> is set.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Queue the task</span><span class="named-paragraph-number">8.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">caused_by</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">first_task</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) { </span><span class="identifier-syntax">first_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">; </span><span class="identifier-syntax">last_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">last_task</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">last_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">caused_by</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">description</span><span class="plain-syntax">, </span><span class="string-syntax">" from [%d]"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">caused_by</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">description</span><span class="plain-syntax">, </span><span class="string-syntax">" from %S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">task_queue_is_closed</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"offending task was: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="1-htc.html#SP12" class="function-link"><span class="function-syntax">Sequence::write_task</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"too late to schedule further compilation tasks"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">TASK_QUEUE_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"queued:    "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="1-htc.html#SP12" class="function-link"><span class="function-syntax">Sequence::write_task</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-htc.html#SP8">&#167;8</a> (twice).</li></ul>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Here the chimes of midnight sound:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::allow_no_further_queued_tasks</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Sequence::allow_no_further_queued_tasks</span></span>:<br/><a href="1-htc.html#SP2_13">&#167;2.13</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">task_queue_is_closed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>So here is where the work is done, and the <span class="extract"><span class="extract-syntax">last_task_undetaken</span></span> advances:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::undertake_queued_tasks</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Sequence::undertake_queued_tasks</span></span>:<br/><a href="1-htc.html#SP2_11">&#167;2.11</a>, <a href="1-htc.html#SP2_13">&#167;2.13</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">do</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">first_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">last_task_undetaken</span><span class="plain-syntax">) </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">last_task_undetaken</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">last_task_undetaken</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">save_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">save_horizon</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">save</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">current_sentence_when_queued</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            (*(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">agent</span><span class="plain-syntax">))(</span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">TASK_QUEUE_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"completed: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="1-htc.html#SP12" class="function-link"><span class="function-syntax">Sequence::write_task</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">save</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_task</span><span class="plain-syntax"> = </span><span class="identifier-syntax">save_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_horizon</span><span class="plain-syntax"> = </span><span class="identifier-syntax">save_horizon</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">save</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>At the end of compilation, the queue ought to be empty, but just in case:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::throw_error_if_subtasks_remain</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Sequence::throw_error_if_subtasks_remain</span></span>:<br/><a href="1-htc.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">first_task</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">first_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">last_task_undetaken</span><span class="plain-syntax">) </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">last_task_undetaken</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><a href="1-htc.html#SP12" class="function-link"><span class="function-syntax">Sequence::write_from</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"there are compilation tasks never reached"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::backtrace</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Sequence::backtrace</span></span>:<br/>Using Problems - <a href="2-up.html#SP3_1">&#167;3.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">d</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">d</span><span class="plain-syntax">++ == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"During compilation task: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"caused by compilation task: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="1-htc.html#SP12" class="function-link"><span class="function-syntax">Sequence::write_task</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">DL</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">caused_by</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"During bench %S\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_sequence_bench</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>And these are used for logging:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::write_from</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Sequence::write_from</span></span>:<br/><a href="1-htc.html#SP11">&#167;11</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><a href="1-htc.html#SP12" class="function-link"><span class="function-syntax">Sequence::write_task</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next_task</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::write_task</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Sequence::write_task</span></span>:<br/><a href="1-htc.html#SP8_1">&#167;8.1</a>, <a href="1-htc.html#SP10">&#167;10</a>, <a href="1-htc.html#SP11">&#167;11</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">compilation_subtask</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"[NULL]\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"[%d] %S\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">description</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>The final step is to verify that the Inter we have produced is correct:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Sequence::lint_inter</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Sequence::lint_inter</span></span>:<br/><a href="1-htc.html#SP2_13">&#167;2.13</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">InterInstruction::tree_lint</span><span class="plain-syntax">(</span><span class="identifier-syntax">Emit::tree</span><span class="plain-syntax">());</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="1-wtc.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresscurrentchapter">1</li><li class="progresssection"><a href="1-cm.html">cm</a></li><li class="progresssection"><a href="1-cp.html">cp</a></li><li class="progresssection"><a href="1-wtc.html">wtc</a></li><li class="progresscurrent">htc</li><li class="progresssection"><a href="1-cp2.html">cp2</a></li><li class="progresssection"><a href="1-pp.html">pp</a></li><li class="progresssection"><a href="1-cs.html">cs</a></li><li class="progresssection"><a href="1-inaa.html">inaa</a></li><li class="progresssection"><a href="1-itc.html">itc</a></li><li class="progresssection"><a href="1-gtg.html">gtg</a></li><li class="progresschapter"><a href="2-up.html">2</a></li><li class="progresschapter"><a href="3-pc.html">3</a></li><li class="progressnext"><a href="1-cp2.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

